﻿CREATE PROCEDURE [dbo].[DetachDatabase]
	@dbName NVARCHAR(200)
AS
BEGIN
	DECLARE @query varchar(2000)
	IF EXISTS(SELECT * FROM [master].[dbo].[sysdatabases] WHERE name = @dbName)
	BEGIN
		EXEC [dbo].[CloseExistsDbConnection] @dbName = @dbName

		SET @query = 'EXEC master.dbo.sp_detach_db @dbname = N''' + @dbName + ''', @skipchecks = ''false'''
		EXEC (@query)
	END
END